﻿Public Module UserBLL
    Function Login(ByVal username As String, ByVal password As String) As Boolean
        Dim user As New UserInfo
        user.UserName = username
        user.PassWord = password
        Return UserDAL.Login(user)
    End Function
    ''' <summary>
    ''' 获取所有用户信息
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetUserInfo() As List(Of UserInfo)
        Dim userInfoList As New List(Of UserInfo)
        Dim ds As New DataSet
        ds = UserDAL.GetUserInfo()
        Dim dt As New DataTable
        If ds.Tables.Count > 0 Then
            dt = ds.Tables.Item(0)
        Else
            Return userInfoList
        End If

        For Each item As DataRow In dt.Rows
            Dim user As New UserInfo
            user.UserName = item("username").ToString
            user.Address = item("address").ToString
            user.BirthTime = item("birthtime").ToString
            user.role = item("role").ToString
            user.Sex = item("sex").ToString
            user.ID = item("id").ToString
            userInfoList.Add(user)
        Next
        Return userInfoList
    End Function

    Function Register(ByVal user As UserInfo) As Boolean
        If UserDAL.Regitser(user) > 0 Then
            Return True
        Else
            Return False
        End If
    End Function
    Function GetUserInfoByID(ByVal ID As String) As UserInfo
        Dim user As New UserInfo
        Dim ds As New DataSet
        ds = UserDAL.GetUserInfoByID(ID)
        Dim dt As New DataTable
        If ds.Tables.Count > 0 Then
            dt = ds.Tables.Item(0)
        Else
            Return user
        End If

        If dt.Rows.Count > 0 Then
            For Each item As DataRow In dt.Rows
                user.UserName = item("username").ToString
                user.Address = item("address").ToString
                user.BirthTime = item("birthtime").ToString
                user.role = item("role").ToString
                user.Sex = item("sex").ToString
                user.ID = item("id").ToString
            Next
        End If
        Return user
    End Function

    Function UpdataUser(ByVal user As UserInfo) As Boolean
        Return UserDAL.UpdateUser(user)
        Return False
    End Function

    Function DeleteUsers(ByVal idList As IList(Of Integer)) As Boolean
        Return UserDAL.DeleteUsers(idList)
        Return False
    End Function


End Module
